package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.bean.DataBean;
import com.bw.service.DataBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author admin
 * @date 2025年10月13日 09:52
 */
@RestController
public class DataBeanController {
    @Autowired
    private DataBeanService dataBeanService;

    @RequestMapping("s1")
    public JSONObject select1(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject co1 = new JSONObject();
        co1.put("id","name");
        co1.put("name","章节名称");
        columns.add(co1);

        JSONObject co2 = new JSONObject();
        co2.put("id","cta");
        co2.put("name","播放次数");
        columns.add(co2);

        JSONObject co3 = new JSONObject();
        co3.put("id","ctb");
        co3.put("name","播放时长");
        columns.add(co3);

        JSONObject co4 = new JSONObject();
        co4.put("id","ctc");
        co4.put("name","观看人数");
        columns.add(co4);

        JSONObject co5 = new JSONObject();
        co5.put("id","ctd");
        co5.put("name","人均观看时长");
        columns.add(co5);

        List<DataBean> beans = dataBeanService.select1();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getName());
            row.put("cta",bean.getCta());
            row.put("ctb",bean.getCtb());
            row.put("ctc",bean.getCtc());
            row.put("ctd",bean.getCtd());
            rows.add(row);
        }
        return result;
    }

    @RequestMapping("s2")
    public JSONObject select2(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONArray data = new JSONArray();
        result.put("data",data);

        List<DataBean> beans = dataBeanService.select2();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getName());
            row.put("value",bean.getCta());
            data.add(row);
        }

        return result;
    }

    @RequestMapping("s3")
    public JSONObject select3(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray mapData = new JSONArray();
        data.put("mapData",mapData);
        data.put("valueName","订单总额");

        List<DataBean> beans = dataBeanService.select3();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getName());
            row.put("value",bean.getCta());
            mapData.add(row);
        }
        return result;
    }

    @RequestMapping("s4")
    public JSONObject select4(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");


        List<DataBean> beans = dataBeanService.select4();
        for (DataBean bean : beans) {
            result.put("data",bean.getCta());
        }

        return result;
    }
}
